const db = require("../../dataBase/db");
module.exports = {
  url: "/user/search",
  method: "get",
  controller: async function(ctx, next) {
    console.log("执行查询");
    let obj = ctx.params;
    let repos = await db.getList();
    console.log("repos", repos);
    let list = repos.filter(function(item) {
      if (item.name === obj.name || item.age === obj.age) return item;
    });
    let result = {};
    if (list.length > 0) {
      result = {
        data: list,
        msg: "查询成功!"
      };
    } else {
      result = {
        data: db.getList(),
        msg: "获取列表！"
      };
    }
    ctx.body = result;
  }
};
